package com.mdd.admin.controller.course;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.course.ICourseCategoryService;
import com.mdd.admin.validate.course.CourseCategoryParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.validate.course.CourseParam;
import com.mdd.admin.vo.course.CourseCategoryListVo;
import com.mdd.admin.vo.course.CourseCategoryDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 课程分类管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/course/category")
public class CourseCategoryController {

    @Resource
    ICourseCategoryService iCourseCategoryService;

    /**
     * 课程分类列表
     *
     * @author panweiliang
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(
                       @RequestParam Map<String, String> params) {
        List<CourseCategoryListVo> list = iCourseCategoryService.list(params);
        return AjaxResult.success(list);
    }


    /**
     * 课程分类列表
     *
     * @author panweiliang
     * @param level 层级
     * @return Object
     */
    @GetMapping("/get")
    public Object get(@RequestParam("level") Integer level) {
        List<CourseCategoryListVo> list = iCourseCategoryService.listByLevel(level);
        return AjaxResult.success(list);
    }


    /**
     * 课程分类详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CourseCategoryDetailVo detail = iCourseCategoryService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 课程分类新增
     *
     * @author panweiliang
     * @param courseCategoryParam 参数
     * @return Object
     */
    @Log(title = "课程分类新增")
    @PostMapping("/add")
    public Object add(@Validated(value = CourseCategoryParam.create.class) @RequestBody CourseCategoryParam courseCategoryParam) {
        iCourseCategoryService.add(courseCategoryParam);
        return AjaxResult.success();
    }

    /**
     * 课程分类编辑
     *
     * @author panweiliang
     * @param courseCategoryParam 参数
     * @return Object
     */
    @Log(title = "课程分类编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = CourseCategoryParam.update.class) @RequestBody CourseCategoryParam courseCategoryParam) {
        iCourseCategoryService.edit(courseCategoryParam);
        return AjaxResult.success();
    }

    /**
     * 课程分类删除
     *
     * @author panweiliang
     * @param courseCategoryParam 参数
     * @return Object
     */
    @Log(title = "课程分类删除")
    @PostMapping("/del")
    public Object del(@Validated(value = CourseCategoryParam.delete.class) @RequestBody CourseCategoryParam courseCategoryParam) {
        iCourseCategoryService.del(courseCategoryParam.getId());
        return AjaxResult.success();
    }

    /**
     * 课程分类状态
     *
     * @author panweiliang
     * @param courseCategoryParam 课程分类参数
     * @return AjaxResult
     */
    @Log(title = "课程分类状态")
    @PostMapping("/change")
    public AjaxResult change(@Validated(value = CourseCategoryParam.change.class)
                             @RequestBody CourseCategoryParam courseCategoryParam) {
        return AjaxResult.success(iCourseCategoryService.changeStatus(courseCategoryParam.getId()));
    }

}
